<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="js/jquery-3.4.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="./js/city.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			$(function(){
				let selects = $('#city>select');
				//把后三个禁用
				for(let i = 1 ; i < selects.length ; i++){
					selects[i].disabled = true;
				}
				//填充一级城市列表
				$.each(citys, function(k,v){
					selects[0].append(new Option(k,k));
				});
				//一级城市下拉选中事件
				$(selects[0]).change(function(){
					selects[1].options.length = 1;
					selects[2].options.length = 1;
					selects[3].options.length = 1;
					selects[1].disabled = false;
					selects[2].disabled = true;
					selects[3].disabled = true;
					//填充二级城市列表
					$.each(citys[this.value], function(k,v){
						selects[1].append(new Option(k,k));
					});
					
				});
				//二级城市下拉选中事件
				$(selects[1]).change(function(){
					selects[2].options.length = 1;
					selects[3].options.length = 1;
					selects[2].disabled = false;
					selects[3].disabled = true;
					//填充三级城市列表
					$.each(citys[selects[0].value][this.value], function(k,v){
						selects[2].append(new Option(k,k));
					});
				});
				//三级城市下拉选中事件
				$(selects[2]).change(function(){
					selects[3].options.length = 1;
					selects[3].disabled = false;
					//填充三级城市列表
					$.each(citys[selects[0].value][selects[1].value][this.value], function(k,v){
						selects[3].append(new Option(v,v));
					});
				});
				
			});
			
		</script>
	</head>
	<body>
		<form id="city" action="" method="">
			<select name="city1">
				<option value="">请选择</option>
			</select>
			<select name="city2">
				<option value="">请选择</option>
			</select>
			<select name="city3">
				<option value="">请选择</option>
			</select>
			<select name="city4">
				<option value="">请选择</option>
			</select>
		</form>
	</body>
</html>
